#pragma once

#include <memory>
#include <cstring>
#include <iostream>
namespace mystl 
{
    class string
    {
    public:
        class Iterator
        {
        public:
            Iterator(char* ptr)
                :_ptr(ptr)
            {}
            Iterator& operator++();
            bool operator!=(const Iterator& other);
            char& operator*();
            char& operator->();
        private:
            char* _ptr = nullptr;
        };
        string()
            :_str((char*)malloc(sizeof(char) * 2)),
            _start(_str),
            _size(_start),
            _cap(_start + 2)
        {}
        Iterator begin()
        {
            return Iterator(_start);
        }
        Iterator end()
        {
            return Iterator(_size);
        }
        string(string& s)
        {
            size_t size = strlen(s._str);
            _str = (char*)malloc(size*sizeof(char));
            _start = _str;
            for(size_t i = 0;i<size;++i)
            {
                _str[i] = s._str[i];
            }
            _size = _start + size;
        }
        string& operator += (const char*);
        string& operator +=(const string& str);
        bool find(const char val);
        void push_back(const char val);
        void pop_back();
        void erase(const char val);
    private:
        char* _str = nullptr;
        char* _start = nullptr;
        char* _size = nullptr;
        char* _cap = nullptr;
    };
}